
package com.grt192.spot.controller;

import com.grt192.core.EventController;
import com.grt192.mechanism.event.WallHuggable;
import com.grt192.spot.mechanism.WallHugger.WallHuggingBase;

/**
 * A 'bouncing' wallhugging algorithm.
 * @author ajc
 */
public class WallHugger extends EventController implements WallHuggable{
    private final WallHuggingBase base;

    public WallHugger(WallHuggingBase base ){
        this.base = base;
        setPrinting(true);
    }

    /** Start WallHugging by doing a slight turn to make initial hit on wall **/
    public void start(){
        super.start();
        log("Start drive");
         //we only start slight turn to start, and change behavior based on wallHuggable events
        base.driveTurn();
    }

    public void startListening() {
        log("Start listening");
        base.addWallHuggingController(this);
    }

    public void stopListening() {
        log("stop listening");
        base.removeWallHuggingController(this);
    }

    /** Does a hard turn to avoid bumping the wall when we are almost hitting it **/
    public void tooClose() {
        log("too close: turn");
        base.turn();
    }

    /** Does a slight turn to run into a wall. **/
    public void tooFar() {
        log("too far: driveturn");
        base.driveTurn();
    }

}
